﻿using Md.Api.Model;
using Md.Api.Model.Manage.MdArticle.Request;
using Md.Api.Service.Manage.MdArticle;
using Microsoft.AspNetCore.Mvc;

namespace Md.Api.Controllers.Manage;
/// <summary>
/// 文章
/// </summary>
[ApiController]
[Produces("application/json")]
[Route("md-api/manage/md/article")]
public class MdArticleController : ControllerBase
{
    /// <summary>
    /// 通过编号删除文章服务
    /// </summary>
    public DeleteMdArticleByIdService deleteMdArticleByIdService { get; set; }
    /// <summary>
    /// 通过编号删除文章
    /// </summary>
    /// <param name="articleIds">文章编号多个逗号分割（1,2,3...）</param>
    /// <param name="signModel">加密实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpDelete("{articleIds}")]
    public async Task<ResponseMessageModel> DeleteMdArticleById(string articleIds, [FromQuery] RequestSignModel signModel)
    {
        var model = new RequestDeleteMdArticleByIdModel();

        model.Ids = articleIds;
        model.TimesTamp = signModel.TimesTamp;
        model.Mac = signModel.Mac;
        model.Ip = signModel.Ip;
        model.Sign = signModel.Sign;
        model.Version = signModel.Version;
        model.Token = signModel.Token;

        return await Task.Run(() => deleteMdArticleByIdService.Execute(model));
    }

    /// <summary>
    /// 添加文章服务
    /// </summary>
    public InsertMdArticleService insertMdArticleService { get; set; }
    /// <summary>
    /// 添加文章
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpPost]
    public async Task<ResponseMessageModel> InsertMdArticle([FromBody] RequestInsertMdArticleModel model)
    {
        return await Task.Run(() => insertMdArticleService.Execute(model));
    }

    /// <summary>
    /// 通过编号更新文章服务
    /// </summary>
    public UpdateMdArticleByIdService updateMdArticleByIdService { get; set; }
    /// <summary>
    /// 通过编号更新文章
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpPut]
    public async Task<ResponseMessageModel> UpdateMdArticleById([FromBody] RequestUpdateMdArticleByIdModel model)
    {
        return await Task.Run(() => updateMdArticleByIdService.Execute(model));
    }

    /// <summary>
    /// 通过编号获取文章服务
    /// </summary>
    public GetMdArticleByIdService getMdArticleByIdService { get; set; }
    /// <summary>
    /// 通过编号获取文章
    /// </summary>
    /// <param name="articleId">文章编号</param>
    /// <param name="signModel">加密实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpGet("{articleId}")]
    public async Task<ResponseMessageModel> GetMdArticleById(long articleId, [FromQuery] RequestSignModel signModel)
    {
        var model = new RequestGetMdArticleByIdModel();

        model.ArticleId = articleId;
        model.TimesTamp = signModel.TimesTamp;
        model.Mac = signModel.Mac;
        model.Ip = signModel.Ip;
        model.Sign = signModel.Sign;
        model.Version = signModel.Version;
        model.Token = signModel.Token;

        return await Task.Run(() => getMdArticleByIdService.Execute(model));
    }

    /// <summary>
    /// 获取文章列表服务
    /// </summary>
    public GetMdArticleListService getMdArticleListService { get; set; }
    /// <summary>
    /// 获取文章列表
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [Route("list"), HttpPost]
    public async Task<ResponseMessageModel> GetMdArticleList([FromBody] RequestGetMdArticleListModel model)
    {
        return await Task.Run(() => getMdArticleListService.Execute(model));
    }

    /// <summary>
    /// 分页获取文章列表服务
    /// </summary>
    public GetMdArticlePageListService getMdArticlePageListService { get; set; }
    /// <summary>
    /// 分页获取文章列表
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [Route("listPage"), HttpPost]
    public async Task<ResponseMessageModel> GetMdArticlePageList([FromBody] RequestGetMdArticlePageListModel model)
    {
        return await Task.Run(() => getMdArticlePageListService.Execute(model));
    }
}

